#include "stdafx.h"
#include "MenuExample.h"

MenuExample::MenuExample(){
    m_menu = 0;
}

MenuExample::~MenuExample(){
    m_menu = 0;
}

void MenuExample::loadFile(const String& fileName, FCView *view){
    FCUIXml::loadFile(fileName, view);
    getTabPage(L"TabPage")->addEvent((FCTouchEventCallBack*)this, FCEventID_TouchDown, this);
    m_menu = new FCMenu();
    m_menu->setVisible(false);
    m_menu->setPopup(true);
    FCSize menuSize = {100, 20};
    m_menu->setSize(menuSize);
    getNative()->addView(m_menu);
    m_menu->addEvent((FCMenuItemTouchEventCallBack*)this, FCEventID_MenuItemClick, this);
    for (int i = 0; i < 10; i++)
    {
        FCMenuItem *menuItem = new FCMenuItem();
        menuItem->setText(L"菜单项");
        m_menu->addItem(menuItem);
        for (int j = 0; j < 10; j++)
        {
            FCMenuItem *subMenuItem = new FCMenuItem();
            subMenuItem->setText(L"子菜单项");
            menuItem->addItem(subMenuItem);
            for (int z = 0; z < 10; z++)
            {
                FCMenuItem *sunMenuItem = new FCMenuItem();
                sunMenuItem->setText(L"孙菜单项");
                subMenuItem->addItem(sunMenuItem);
            }
            subMenuItem->getDropDownMenu()->setSize(menuSize);
        }
        menuItem->getDropDownMenu()->setSize(menuSize);
    }
}

void MenuExample::callTouchEvent(String eventName, Object sender, FCTouchInfo touchInfo, Object invoke){
    if (touchInfo.m_secondTouch)
    {
        m_menu->setLocation(getNative()->getTouchPoint());
        m_menu->show();
        getNative()->invalidate();
    }
}

void MenuExample::callMenuItemTouchEvent(String eventName, Object sender, FCMenuItem *item, FCTouchInfo touchInfo, Object invoke){
}
